var observationrecord={};
observationrecord.currentObj;
observationrecord.loadList=function (pageNo,isfirst){
	var queryStr=$("#obsrecord_queryText").val();
	$('#obsRecordTable').empty();
	var params = {pageSize:3,pageNo:pageNo,queryStr:queryStr};
	var config={columns:[{
		headerText:'井名',
		name:'wellName'
	},{
		headerText:'日期',
		name:'date'
	},{
		headerText:'班次',
		name:'order_'
	},{
		headerText:'接班井深/米',
		name:'depthBegin'
	},{
		headerText:'交班井深/米',
		name:'depthEnd'
	},{
		headerText:'值班人',
		name:'personOnDuty'
	},{
		headerText:'接班人',
		name:'personTakeOver'
	},{
		headerText:'审核人',
		name:'auditer'
	},{
		headerText:'录入时间',
		name:'dateInput'
	},{
		headerText:'录入人',
		name:'owner'
	},{
		headerText:'操作',
		name:'',
		renderer:function(str) {
		return '<input type="button" onclick="observationrecord.openDetailDialog('+this.id+')" value="查看">'+
		'<input type="button" onclick="observationrecord.openUpdateDialog('+this.id+')" value="修改">'+
		'<input type="button" onclick="observationrecord.doDelete('+this.id+')" value="删除">';
	} 
	}
	],url:basePath+'app/obsRecord/loadList',params:params};
	$('#obsRecordTable').table(config,true,isfirst);
}
//新增操作
observationrecord.openAddDialog=function (){
	observationrecord.cleanAddDialog();
	$("#addObsRecordDialog").dialog({ modal: true ,width: 1200});
}
observationrecord.cleanAddDialog=function (){
	document.getElementById("add_form").reset();
	$("#addObsRecord_date").datepicker();
	$.post(basePath+'app/obsRecord/getWellList', {}, function(data) {
		var l=$("#addObsRecord_wellId");
		l.empty();
		for(var i in data){
			$("<option value='"+data[i].id+"'>"+data[i].name+"</option>").appendTo(l);
		}
	});
}
observationrecord.callback=function (){
	try{
		$("#addObsRecordDialog").dialog("close");
	}catch(error){
	}
	try{
		$("#updateObsRecordDialog").dialog("close");
	}catch(error){
	}
}
//查看操作
observationrecord.openDetailDialog=function (wellId){
	observationrecord.refreshDetailDialog(wellId);
	$("#detailObsRecordDialog").dialog({ modal: false ,width: 1200});
}
observationrecord.refreshDetailDialog=function (wellId){
	var wg;
	for(var i in window.gridcache){
		if(wellId==window.gridcache[i].id){
			wg=window.gridcache[i];
			break;
		}
	}
	$("#detailObsRecord_date").val(wg.date);
	$("#detailObsRecord_wellName").val(wg.wellName);
	$("#detailObsRecord_order_").val(wg.order_);
	$("#detailObsRecord_depthBegin").val(wg.depthBegin);
	$("#detailObsRecord_depthEnd").val(wg.depthEnd);
	$("#detailObsRecord_rockLayer").val(wg.rockLayer);
	$("#detailObsRecord_timeLate").val(wg.timeLate);
	$("#detailObsRecord_countLujing").val(wg.countLujing);
	$("#detailObsRecord_depthRockLujing").val(wg.depthRockLujing);
	$("#detailObsRecord_countPackage").val(wg.countPackage);
	$("#detailObsRecord_lengthTeam").val(wg.lengthTeam);
	$("#detailObsRecord_densityRelative").val(wg.densityRelative);
	$("#detailObsRecord_viscosity").val(wg.viscosity);
	$("#detailObsRecord_volSand").val(wg.volSand);
	$("#detailObsRecord_lostWater").val(wg.lostWater);
	$("#detailObsRecord_mudpie").val(wg.mudpie);
	$("#detailObsRecord_ph").val(wg.ph);
	$("#detailObsRecord_shearForce").val(wg.shearForce);
	$("#detailObsRecord_clPerL").val(wg.clPerL);
	$("#detailObsRecord_drillPressure").val(wg.drillPressure);
	$("#detailObsRecord_pumpPressuer").val(wg.pumpPressuer);
	$("#detailObsRecord_countRotationPerM").val(wg.countRotationPerM);
	$("#detailObsRecord_dispacementPerS").val(wg.dispacementPerS);
	$("#detailObsRecord_lengthHeader").val(wg.lengthHeader);
	$("#detailObsRecord_lengthZuantingAndJunction").val(wg.lengthZuantingAndJunction);
	
	$("#detailObsRecord_lengthQuxintong").val(wg.lengthQuxintong);
	$("#detailObsRecord_lengthZuangan").val(wg.lengthZuangan);
	$("#detailObsRecord_lengthFangru").val(wg.lengthFangru);
	$("#detailObsRecord_depthWell").val(wg.depthWell);
	$("#detailObsRecord_inclination").val(wg.inclination);
	$("#detailObsRecord_orientationDegree").val(wg.orientationDegree);
	$("#detailObsRecord_rockfeature").val(wg.rockfeature);
	$("#detailObsRecord_oilGasWater").val(wg.oilGasWater);
	$("#detailObsRecord_projIntroduction").val(wg.projIntroduction);
	$("#detailObsRecord_other").val(wg.other);
	$("#detailObsRecord_personOnDuty").val(wg.personOnDuty);
	$("#detailObsRecord_personTakeOver").val(wg.personTakeOver);
	$("#detailObsRecord_auditer").val(wg.auditer);
	$("#detailObsRecord_owner").text(wg.owner);
	$("#detailObsRecord_dateInput").text(wg.dateInput);
}
//修改操作
observationrecord.openUpdateDialog=function (wellId){
	observationrecord.refreshUpdateDialog(wellId);
	$("#updateObsRecordDialog").dialog({ modal: true ,width: 1200});
}
observationrecord.refreshUpdateDialog=function (wellId){
	var wg;
	for(var i in window.gridcache){
		if(wellId==window.gridcache[i].id){
			wg=window.gridcache[i];
			break;
		}
	}
	observationrecord.currentObj=wg;
	$("#updateObsRecord_id").val(wg.id);
	$("#updateObsRecord_date").datepicker();
	$("#updateObsRecord_date").val(wg.date);
	$.post(basePath+'app/obsRecord/getWellList', {}, function(data) {
		var l=$("#updateObsRecord_wellId");
		l.empty();
		for(var i in data){
			$("<option value='"+data[i].id+"' "+(wg.wellId==data[i].id?"selected='selected'":"")+">"+data[i].name+"</option>").appendTo(l);
		}
	});
	$("#updateObsRecord_order_").val(wg.order_);
	$("#updateObsRecord_depthBegin").val(wg.depthBegin);
	$("#updateObsRecord_depthEnd").val(wg.depthEnd);
	$("#updateObsRecord_rockLayer").val(wg.rockLayer);
	$("#updateObsRecord_timeLate").val(wg.timeLate);
	$("#updateObsRecord_countLujing").val(wg.countLujing);
	$("#updateObsRecord_depthRockLujing").val(wg.depthRockLujing);
	$("#updateObsRecord_countPackage").val(wg.countPackage);
	$("#updateObsRecord_lengthTeam").val(wg.lengthTeam);
	$("#updateObsRecord_densityRelative").val(wg.densityRelative);
	$("#updateObsRecord_viscosity").val(wg.viscosity);
	$("#updateObsRecord_volSand").val(wg.volSand);
	$("#updateObsRecord_lostWater").val(wg.lostWater);
	$("#updateObsRecord_mudpie").val(wg.mudpie);
	$("#updateObsRecord_ph").val(wg.ph);
	$("#updateObsRecord_shearForce").val(wg.shearForce);
	$("#updateObsRecord_clPerL").val(wg.clPerL);
	$("#updateObsRecord_drillPressure").val(wg.drillPressure);
	$("#updateObsRecord_pumpPressuer").val(wg.pumpPressuer);
	$("#updateObsRecord_countRotationPerM").val(wg.countRotationPerM);
	$("#updateObsRecord_dispacementPerS").val(wg.dispacementPerS);
	$("#updateObsRecord_lengthHeader").val(wg.lengthHeader);
	$("#updateObsRecord_lengthZuantingAndJunction").val(wg.lengthZuantingAndJunction);
	
	$("#updateObsRecord_lengthQuxintong").val(wg.lengthQuxintong);
	$("#updateObsRecord_lengthZuangan").val(wg.lengthZuangan);
	$("#updateObsRecord_lengthFangru").val(wg.lengthFangru);
	$("#updateObsRecord_depthWell").val(wg.depthWell);
	$("#updateObsRecord_inclination").val(wg.inclination);
	$("#updateObsRecord_orientationDegree").val(wg.orientationDegree);
	$("#updateObsRecord_rockfeature").val(wg.rockfeature);
	$("#updateObsRecord_oilGasWater").val(wg.oilGasWater);
	$("#updateObsRecord_projIntroduction").val(wg.projIntroduction);
	$("#updateObsRecord_other").val(wg.other);
	$("#updateObsRecord_personOnDuty").val(wg.personOnDuty);
	$("#updateObsRecord_personTakeOver").val(wg.personTakeOver);
	$("#updateObsRecord_auditer").val(wg.auditer);
	$("#updateObsRecord_owner").text(wg.owner);
	$("#updateObsRecord_dateInput").text(wg.dateInput);
}
//删除操作
observationrecord.doDelete=function (wellId){
	var i=window.confirm("确认删除？");
	if(i==true){
		$.post(basePath+"app/obsRecord/doDeleteRecord", {recordId:wellId}, function(data) {
			observationrecord.loadList();//修改刷新为当前页
		});
	}
}
$(function() {
	currentModule=observationrecord;//当前模块
	observationrecord.loadList(1,true);
	$("#wellQuery").bind("keyup",function (event){
		if (event.keyCode=="13"){
			observationrecord.loadList(1);
		}
	});
});